#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e2 + 10, INF = 0x3f3f3f3f;

int n;
int cnt[5], a[N];
vector<pair<int, int>> b[5];
int f[N][N][5];

int at(char c) {
    if (c == 'W') return 1;
    if (c == 'I') return 2;
    if (c == 'N') return 3;
    return 4;
}

void solve()
{
    cin >> cnt[1] >> cnt[2] >> cnt[3] >> cnt[4];
    for (int i = 1;i <= 4;i++)
        for (int j = 1;j <= cnt[i];j++) {
            char x, y; cin >> x >> y;
            b[i].push_back({ at(x),at(y) });
        }
    string s; cin >> s;n = s.length();
    for (int i = 0;i < s.length();i++) a[i + 1] = at(s[i]);

    for (int i = 1;i <= n;i++)
        for (int t = 1;t <= 4;t++)
            f[i][i][t] = a[i] == t;

    for (int len = 2;len <= n;len++)
        for (int l = 1;l + len - 1 <= n;l++) {
            int r = l + len - 1;
            for (int t = 1;t <= 4;t++)
                for (int k = 1;k < n;k++)
                    for (auto [x, y] : b[t])
                        f[l][r][t] |= f[l][k][x] & f[k + 1][r][y];
        }

    int flag = 1;
    for (int i = 1;i <= 4;i++)
        if (f[1][n][i]) {
            if (i == 1) cout << 'W';
            if (i == 2) cout << 'I';
            if (i == 3) cout << 'N';
            if (i == 4) cout << 'G';
            flag = 0;
        }
    if (flag) cout << "The name is wrong!";
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}